<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page import="com.crm.util.RequestEx"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>  
    <title>CRM客户管理</title>
    <link rel="icon" mce_href="<%=path%>/images/title_logo.ico" href="<%=path%>/images/title_logo.ico" type="image/x-ico"/>
    <link rel="shortcut icon" mce_href="<%=path%>/images/title_logo.ico" href="<%=path%>/images/title_logo.ico" type="image/x-ico"/>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta content="text/html;charset=utf-8" http-equiv="Content-Type"/>	
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/easyui1.3.2/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="<%=path%>/js/easyui1.3.2/themes/icon.css">	
	<script type="text/javascript" src="<%=path%>/js/easyui1.3.2/jquery-1.8.0.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/easyui1.3.2/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="<%=path%>/js/easyui1.3.2/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript" src="<%=path%>/js/My97DatePicker/WdatePicker.js"></script>
	<style type="text/css">
		body,td,th,div{
 			font-size:12px;
		}
	</style>
  </head>
  
  <body style="margin:0;padding:0" class="easyui-layout">
    <script type="text/javascript">

	var datagrid;
	var url = "<%=path%>/invpp.do";

	//恢复数据
	function recoverInventoryPp(){
		var node = datagrid.datagrid('getSelected');
		$.messager.confirm('提示','<br>您确定恢复选中的数据吗?',function(r){ 
			if(r){ 
				var insids = "'" + node.insid + "'";

				$.ajax({
					url : url + '?method=recoverInventoryPp',
					type : 'POST',
					data : {insids : insids},
					success : function(data, textStatus) {
						if('ok' == data){
							datagrid.datagrid('load');
						}else{								
							$.messager.alert('提示', data, 'info');
						}		
					}
				});
			} 
		});
	}

	//彻底删除数据
	function reallyDeleteInventoryPp(){
		var node = datagrid.datagrid('getSelected');
		$.messager.confirm('提示','<br>您确定彻底删除选中的数据吗?',function(r){ 
			if(r){ 
				var insids = "'" + node.insid + "'";

				$.ajax({
					url : url + '?method=reallyDeleteInventoryPp',
					type : 'POST',
					data : {insids : insids},
					success : function(data, textStatus) {
						if('ok' == data){
							datagrid.datagrid('load');
						}else{								
							$.messager.alert('提示', data, 'info');
						}		
					}
				});
			} 
		});
	}
	
	//定义datagrid列模型
	var columns = [[
		{field:'oper',title:'操作',width:120,formatter:formatOper},
		{field:'insid',title:'客户主键',width:20,hidden:true},
		{field:'institution',title:'公司名称',width:100},
		{field:'senddate',title:'送货日期',width:80},
		{field:'goods',title:'采购物品',width:180},
		{field:'amount',title:'数量',width:50},
		{field:'unit',title:'单位',width:50},
		
		{field:'price0',title:'采购单价',width:80,formatter:formatPrice,sortable:true},
		{field:'totalprice0',title:'采购合计金额',width:80,formatter:formatPrice,sortable:true},
		{field:'price1',title:'销售单价',width:80,formatter:formatPrice,sortable:true},
		{field:'totalprice1',title:'销售合计金额',width:80,formatter:formatPrice,sortable:true},

		{field:'grossprofit',title:'毛利润',width:80,formatter:formatPrice},
		{field:'purchaser',title:'采购人',width:60},
		{field:'ordernumber',title:'订单号',width:80},
		{field:'user',title:'使用人',width:60},
		{field:'supplier',title:'供应商',width:180},
		{field:'linkman',title:'联系人',width:80},
		{field:'tel',title:'固定电话',width:120},
		{field:'phone',title:'移动电话',width:120},
		{field:'email',title:'电子邮箱',width:120},
		{field:'address',title:'地址',width:120},
		{field:'remark',title:'备注',width:150},
		{field:'creattime',title:'创建时间',width:100,hidden:true},
		{field:'updatetime',title:'修改时间',width:100,hidden:true},
		{field:'sort',title:'排序',width:30}
	]];

	//入口
	$(function(){
		datagrid = $('#datagrid');
		$(datagrid).datagrid({
			url:url+'?method=getInventoryPpList&islive=N', 
			toolbar:'#tb',
			columns:columns,
			title:'', 
			loadMsg:'正在处理...',
			iconCls:'', 
			nowrap: true, 
			rownumbers: true,
			autoRowHeight: false,
			autoRowWidth: true,             
			animate:true, 
			singleSelect: true,
			collapsible: true, 
			fitColumns: false,//自动充满列
			fit:true,//自动充满浏览器区域
			idField:'insid', 
			showFooter: false,
			striped:true,//斑马线
			pagination:true,
			pageSize:50,
			pageList:[50,100,200,500]
		}); 
	}); 

	//格式化创建时间
	function formatDate(value, row){
		value = value + '';
		if(value == null || value.length == 0){
			return "";
		}
		var yy = '';
		var mo = '';
		var da = '';
		
		var ho = '';
		var mm = '';
		var ss = '';

		var dateTime = '';
		if(value.length > 4){
			yy = value.substr(0, 4);
			dateTime = dateTime + yy;
		}
		if(value.length > 6){
			mo = value.substr(4, 2);
			dateTime = dateTime + '-' + mo;
		}
		if(value.length > 8){
			da = value.substr(6, 2);
			dateTime = dateTime + '-' + da;
		}
		
		if(value.length > 10){
			ho = value.substr(8, 2);
			dateTime = dateTime + ' ' + ho;
		}
		if(value.length > 12){
			mm = value.substr(10, 2);
			dateTime = dateTime + ':' + mm;
		}
		if(value.length >= 14){
			ss = value.substr(12, 2);
			dateTime = dateTime + ':' + ss;
		}
		return dateTime;
	}

	//格式化操作
	function formatOper(value, row){
		var updateOper = "<a href='javascript:recoverInventoryPp();'>恢复数据</a>";
		var deleteOper = "<a href='javascript:reallyDeleteInventoryPp();'>彻底删除</a>";
		return updateOper + '&nbsp;&nbsp;&nbsp;' + deleteOper + '&nbsp;&nbsp;&nbsp;';
	}

	//格式化价格
	function formatPrice(value, row){
		var tempValue = value + '';
		if(tempValue.indexOf(".") > 0){
			var arr = tempValue.split(".");
			if(arr[1].length == 1){
				tempValue = tempValue + "0";
			}else if(arr[1].length > 2){
				tempValue = arr[0] + arr[1].substr(0, 2);
			}
		}else{
			tempValue = tempValue + ".00";
		}
		return tempValue;
	}
	</script>

	<div data-options="region:'center',title:'普票客户回收站'">
		<!-- 表格面板 -->
		<table id="datagrid"></table>
	</div>
  </body>
</html>
